<?php

class DataViewIterator
{

  protected $data;

  protected $index = - 1;

  /**
   *
   * @var DataView
   */
  protected $view;

  public function __construct(&$data, $class = 'DataView')
  {
    $this->data = &$data;
    $this->view = new $class();
  }

  public function getAll()
  {
    $this->reset();

    $data = array();

    while ($obj = $this->next()) {
      $data[] = $obj->getAll();
    }

    return $data;
  }

  public function first()
  {
    $this->reset();
    return $this->next();
  }

  public function next()
  {
    if ($this->index < count($this->data) - 1) {
      $this->index ++;
      $this->view->setData($this->data[$this->index]);
      return $this->current();
    }

    return false;
  }

  public function current()
  {
    return $this->view;
  }

  public function reset()
  {
    $this->index = - 1;
  }

}

?>